<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<title>数据表格</title>
		<link rel="stylesheet" href="../../component/pear/css/pear.css" th:href="@{/component/pear/css/pear.css}" />
		<style>
			.layui-form-item .layui-input-inline {
				width: 23em;
			}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="" lay-filter="rule-form" onsubmit="return false">

					<blockquote class="layui-elem-quote">规则信息</blockquote>
					<div class="layui-form-item" style="display: none">
						<label class="layui-form-label">规则id</label>
						<div class="layui-input-inline">
							<input type="text" name="ruleId"  placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">规则名称</label>
						<div class="layui-input-inline">
							<input type="text" name="ruleName" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">日常采集间隔</label>
						<div class="layui-input-inline">
							<input type="text" name="pageStartRule" required  lay-verify="required|number" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-mid layui-word-aux">单位分钟，最小配置为 15分钟，小于15分钟按照默认15分钟计算</div>
					</div>
				<!--规则信息结束-->
					<blockquote class="layui-elem-quote">列表规则</blockquote>

					<div class="layui-form-item">
						<label class="layui-form-label">url</label>
						<div class="layui-input-inline">
							<input type="text" name="sourceUrl" required  lay-verify="required|url" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-mid layui-word-aux">序号占位符：[pageNo]</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">起始页码</label>
						<div class="layui-input-inline">
							<input type="text" name="pageStartRule" required  lay-verify="required|number" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">结束页码</label>
						<div class="layui-input-inline">
							<input type="text" name="pageEndRule" required  lay-verify="required|number" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">日常采集页码</label>
						<div class="layui-input-inline">
							<input type="text" name="afterInitPageNo" required  lay-verify="required|number" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">列表规则</label>
						<div class="layui-input-inline">
							<input type="text" name="getUrlListRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">url提取规则</label>
						<div class="layui-input-inline">
							<input type="text" name="getUrlRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<!--列表规则结束-->
					<blockquote class="layui-elem-quote">信息规则</blockquote>

					<div class="layui-form-item">
						<label class="layui-form-label">小说名称</label>
						<div class="layui-input-inline">
							<input type="text" name="nameRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">小说作者</label>
						<div class="layui-input-inline">
							<input type="text" name="authorRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">封面地址</label>
						<div class="layui-input-inline">
							<input type="text" name="imageRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">是否保存封面</label>
						<div class="layui-input-inline">
							<input type="checkbox" value="true" name="imageSave" lay-skin="switch" checked>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">字数(万)</label>
						<div class="layui-input-inline">
							<input type="text" name="wordNumRule" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">连载状态</label>
						<div class="layui-input-inline">
							<input type="text" name="updateStatusRule" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">更新标识</label>
						<div class="layui-input-inline">
							<input type="text" name="lastUpdateMarkRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">书籍分类</label>
						<div class="layui-input-inline">
							<input type="text" name="novelTypeRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">关键字</label>
						<div class="layui-input-inline">
							<input type="text" name="keywordsRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">关键字过滤</label>
						<div class="layui-input-inline">
							<input type="text" name="keywordsReplaceRule"  placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-mid layui-word-aux">多个用","分割</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">描述</label>
						<div class="layui-input-inline">
							<input type="text" name="descriptionRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">描述过滤</label>
						<div class="layui-input-inline">
							<input type="text" name="descriptionReplaceRule"  placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-mid layui-word-aux">多个用","分割</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">简介</label>
						<div class="layui-input-inline">
							<input type="text" name="introRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">简介过滤</label>
						<div class="layui-input-inline">
							<input type="text" name="introReplaceRule"  placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-mid layui-word-aux">多个用","分割</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">章节列表</label>
						<div class="layui-input-inline">
							<input type="text" name="chapterListRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">跳过章节数</label>
						<div class="layui-input-inline">
							<input type="text" name="chapterListSkipNoRule" required  lay-verify="required|number" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">章节名称</label>
						<div class="layui-input-inline">
							<input type="text" name="chapterNameRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">章节url</label>
						<div class="layui-input-inline">
							<input type="text" name="chapterUrlRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>

					<!--列表规则结束-->
					<blockquote class="layui-elem-quote">内容规则</blockquote>
					<div class="layui-form-item">
						<label class="layui-form-label">真实章节名称</label>
						<div class="layui-input-inline">
							<input type="text" name="contentNameRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">章节内容</label>
						<div class="layui-input-inline">
							<input type="text" name="contentTextRule" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">内容过滤</label>
						<div class="layui-input-inline">
							<input type="text" name="contentOutStr"  placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">内容标签过滤</label>
						<div class="layui-input-inline">
							<input type="text" name="contentOutLabelRule" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-mid layui-word-aux">多个用","分割，如: "p,a"</div>
					</div>
					<!--内容规则结束-->
					<blockquote class="layui-elem-quote">测试结果</blockquote>

					<div class="layui-form-item layui-form-text" style="padding-right: 10em;">
						<div class="layui-input-block">
							<textarea name="test" placeholder="测试结果" class="layui-textarea testText" style="height: 30em"></textarea>
						</div>
					</div>
					<!--测试结果结束-->
					<hr>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="test">测试</button>
							<button class="layui-btn" lay-submit lay-filter="save">保存</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>

		<script src="../../component/layui/layui.js" th:src="@{/component/layui/layui.js}"></script>
		<script src="../../component/pear/pear.js" th:src="@{/component/pear/pear.js}"></script>
		<script th:inline="javascript">
			layui.use(['table', 'form', 'jquery', 'drawer', 'dropdown'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let drawer = layui.drawer;
				let MODULE_PATH = "/rule/";

				form.val("rule-form",[[${ruleData}]]);

				form.on('submit(test)', function(data){
					let loading = layer.load();
					$.ajax({
						url: MODULE_PATH + "ruleTest",
						dataType: 'json',
						contentType: "application/json;charset=UTF-8",
						type: 'post',
						data: JSON.stringify(data.field),
						success: function (result) {
							layer.close(loading);
							$(".testText").val(result.msg)
						}
					})
				});

				form.on('submit(save)', function(data){
					let loading = layer.load();
					$.ajax({
						url: MODULE_PATH + "add",
						dataType: 'json',
						contentType: "application/json;charset=UTF-8",
						type: 'post',
						data: JSON.stringify(data.field),
						success: function (result) {
							layer.close(loading);
							if(result.success){
								layer.msg("保存成功")
								parent.refreshTable();
								parent.layer.closeAll()
								// form.val("rule-form",{
								// 	"ruleId":result.data["ruleId"]
								// })
							}else{
								layer.msg("保存失败")
							}
						}
					})
				});
			})
		</script>
	</body>
</html>
